package com.industrial.im.controller;

import cn.hutool.core.util.ArrayUtil;
import com.industrial.common.core.web.controller.BaseController;
import com.industrial.common.core.web.domain.AjaxResult;
import com.industrial.common.core.web.page.TableDataInfo;
import com.industrial.common.security.annotation.RequiresPermissions;
import com.industrial.common.security.utils.SecurityUtils;
import com.industrial.im.domain.DispatchKeyItemManagement;
import com.industrial.im.domain.vo.NameAndValueVo;
import com.industrial.im.service.IDispatchKeyItemManagementService;
import com.industrial.im.service.IDispatchStatisticsService;
import com.industrial.system.api.domain.SysUser;
import com.industrial.system.api.model.LoginUser;
import io.swagger.annotations.Authorization;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.*;

@RestController
@RequestMapping("/bigping")
public class BigPingController  extends BaseController {

    @Autowired
    private IDispatchStatisticsService dispatchStatisticsService;

    @Autowired
    private IDispatchKeyItemManagementService dispatchKeyItemManagementService;

    /**
     * <p>
     *     查询任务的数量
     * </p>
     * @return
     */
    @GetMapping("/queryEventItemCount")
    public AjaxResult queryEventItemCount(){
        Map<String, Long> resultMap = dispatchStatisticsService.queryEventItemCount();
        return AjaxResult.success(resultMap);
    }

    /**
     * 查询状态的数量  右一
     * @return
     */
    @GetMapping("/queryStatusCount")
    public AjaxResult queryStatusCount(){
        List<Map<String, Object>> result = dispatchStatisticsService.queryStatusCount();
        return AjaxResult.success(result);
    }

    /**
     * 查询重点事项管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(DispatchKeyItemManagement dispatchKeyItemManagement)
    {
        startPage();
        List<DispatchKeyItemManagement> list = dispatchKeyItemManagementService.selectDispatchKeyItemManagementList(dispatchKeyItemManagement);
        return getDataTable(list);
    }

    /**
     * 重点事项类型占比
     * @return
     */
    @GetMapping("/queryItemTypeCount")
    public AjaxResult queryItemTypeCount(){
        List<Map> maps = dispatchStatisticsService.queryItemTypeCount();
        return AjaxResult.success(maps);
    }


    /**
     * <p>
     *     查询部门的事项数量
     * </p>
     * @return
     */
    @GetMapping("/queryDeptEventItemCount")
    public AjaxResult queryDeptEventItemCount(){
        List<NameAndValueVo> nameAndValueVos = dispatchStatisticsService.queryDeptEventItemCount();
        List<String> xAxis = new ArrayList<>();
        List<String> yAxis = new ArrayList<>();

        for(NameAndValueVo temp : nameAndValueVos){
            xAxis.add(temp.getName());
            yAxis.add(temp.getValue());
        }
        Map<String, List<String>> result = new HashMap<>();
        result.put("xAxis",xAxis);
        result.put("yAxis",yAxis);

        return AjaxResult.success(result);
    }

    /***
     * <p>
     *     事项调度预警
     * </p>
     * @return
     */
    @GetMapping("/sjddyj")
    public AjaxResult sjddyj(){
        Map<String, Object> sjddyj = dispatchStatisticsService.sjddyj();
        return AjaxResult.success(sjddyj);
    }

    /**
     * <p>
     *     查询到期数量
     * </p>
     * @return
     */
    @GetMapping("/queryDqCount")
    public AjaxResult queryDqCount(){
        Map<String, List<String>> result = dispatchStatisticsService.queryDqCount();
        return AjaxResult.success(result);
    }
}
